﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace plust.Content
{
    public class ClienteViewModel : INotifyPropertyChanged, IDataErrorInfo
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private string nombre;
        private string rut;
        private string giro;
        private string direccion;
        private string comuna;
        private string ciudad;

        public string Nombre
        {
            get { return this.nombre; }
            set
            {
                this.nombre = value;
                OnPropertyChanged("Nombre");
            }
        }

        public string Rut
        {
            get { return this.rut; }
            set
            {
                this.rut = value;
                OnPropertyChanged("Rut");
            }
        }

        public string Giro
        {
            get { return this.giro; }
            set
            {
                this.giro = value;
                OnPropertyChanged("Giro");
            }
        }

        public string Direccion
        {
            get { return this.direccion; }
            set
            {
                this.direccion = value;
                OnPropertyChanged("Direccion");
            }
        }

        public string Comuna
        {
            get { return this.comuna; }
            set
            {
                this.comuna = value;
                OnPropertyChanged("Comuna");
            }
        }

        public string Ciudad
        {
            get { return this.ciudad; }
            set
            {
                this.ciudad = value;
                OnPropertyChanged("Ciudad");
            }
        }

        public string Error
        {
            get { return null; }
        }

        public string this[string columnName]
        {
            get
            {
                if (columnName == "Nombre")
                {
                    return string.IsNullOrEmpty(this.nombre) ? "Valor Requerido" : null;
                }

                if (columnName == "Rut")
                {
                    return string.IsNullOrEmpty(this.rut) ? "Valor Requerido" : null;
                }

                if (columnName == "Giro")
                {
                    return string.IsNullOrEmpty(this.giro) ? "Valor Requerido" : null;
                }

                if (columnName == "Direccion")
                {
                    return string.IsNullOrEmpty(this.direccion) ? "Valor Requerido" : null;
                }

                if (columnName == "Ciudad")
                {
                    return string.IsNullOrEmpty(this.ciudad) ? "Valor Requerido" : null;
                }

                if (columnName == "Comuna")
                {
                    return string.IsNullOrEmpty(this.comuna) ? "Valor Requerido" : null;
                }

                return null;
            }
        }

        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
    }
}
